<template>
  <div class="lg_loginwrap" id="loginwrap" style="min-height:422px">
    <div class="lg_loginbox lg_ercode" id="lg_loginbox" tabindex="0" style="outline: 0px; top: 10px; margin-top: 40px;" aria-label="旅行账号登录，点击tab切换聚焦位置" aria-modal="true">
      <h2 class="lg_loginbox_title" id="logintitle">手机动态密码登录</h2>
      <div class="form_wrap" id="dynamicview" style="">
        <dl>
          <dd class="r_input input_country-code" id="dyCcode" code="86"> 中国大陆 86 <a href="javascript:;" aria-label="选择国家码" class="link_code"></a> </dd>
        </dl>
        <dl>
          <dd><input class="r_input bbz-js-iconable-input" type="text" onkeyup="this.value=this.value.replace(/\D/g,&quot;&quot;)" onafterpaste="this.value=this.value.replace(/\D/g,&quot;&quot;)" maxlength="11" id="dyphone" placeholder="注册或绑定手机号" @focus="Focus" v-model="phone" @blur="Focus" @input="Focus">
            <i class="iconfont icon-delete" v-if="iconshow" @click="phone='',iconshow=false"></i>
          </dd>
        </dl>
        <dl style="padding:0">
          <dd id="sliderdddynamic" style="display:none"></dd>
        </dl>
        <dl>
          <dd class="r_input input_auth-code dynamic"><input type="text" id="dypwd" maxlength="8" placeholder="短信动态码" class=" bbz-js-iconable-input" v-model="code">
            <a href="javascript:;" id="sdy" @click="getcode">发送动态码</a>
          </dd>
        </dl>
        <div class="base_error" style="display:none" id="dyerr"></div>
        <div class="login-set"> <label class="auto-login"><input type="checkbox" id="dynamic30d" checked="checked">30天内自动登录</label> </div>
        <dl>
          <dd> <input class="form_btn form_btn--block" id="dylogin" type="submit" value="登   录" @click="login"> </dd>
        </dl>
        <p class="agreement-list"><input type="checkbox" class="agreement-checkbox" style="vertical-align:-2px;margin:3px 3px 3px 4px" checked>阅读并同意旅行的<a href="https://contents.ctrip.com/huodong/privacypolicypc/index?type=0" class="serviceAgreement" target="_black">服务协议</a>和<a href="https://contents.ctrip.com/huodong/privacypolicypc/index?type=1" class="privacyPolicy" target="_black">个人信息保护政策</a></p> <a class="go_prev-step" @click="changeShowNum(1)"><i>&lt;</i>旅行账号登录</a>
      </div>
      <div class="login-code" id="changeScanLogin"> <a title="扫码登录更安全" id="scanLogin" logintype="scan" @click="changeShowNum(2)">扫码登录<i class="icon-ercode"></i></a> </div>
      <div class="nologin" id="nologin" style="display: none;"> <a href="javascript:;" id="btn_nologin">不登录，直接预订<i>&gt;</i></a> </div> <input type="hidden" id="sliderResult">
    </div>
  </div>
</template>

<script>
import code from '@/utils/code.js'
import { mapState } from 'vuex'
export default {
  name: 'LoginPhone',
  data() {
    return {
      iconshow: false,
      phone: '',
      code: ''
    }
  },
  computed: {
    ...mapState({
      istrue: state => {
        return state.login.istrue
      }
    })
  },
  methods: {
    changeShowNum(num) {
      this.$store.dispatch('changeLoginShowNum', num)
    },
    Focus() {
      if (this.phone.length > 0) {
        this.iconshow = true
      } else {
        this.iconshow = false
      }
    },
    getcode() {
      if (this.phone.length == 11) {
        this.code = code(6)
      }
    },
    login() {
      this.$store.dispatch('loginPhone', this.phone)
      let toPath = this.$route.query.redirect
      // console.log(111, toPath)
      setTimeout(() => {
        if (this.istrue == 1) {
          localStorage.setItem('user_phone', this.phone)
          if (toPath) {
            this.$router.push(toPath)
          } else {
            this.$router.push('/hotel')
          }
        } else {
          alert('该手机号未被注册')
          this.$router.push('/register')
        }
      }, 1000)
    }
  }
}
</script>

<style lang="scss" scoped>
h1,
h2,
h3,
h4,
h5,
input {
  font-weight: 400;
  font-family: 'Microsoft YaHei', SimSun, Tahoma, Verdana, Arial, sans-serif;
}
input,
textarea {
  font-size: 12px;
}
.lg_loginwrap {
  position: relative;
  float: right;
  width: 380px;
  min-height: 540px;
  margin-right: -40px;
  .lg_loginbox {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    background: #fff;
    padding: 30px 30px 20px;
    min-height: 370px;
    border-radius: 4px;
    -webkit-box-shadow: 0 1px 6px rgb(0 0 0 / 10%);
    box-shadow: 0 1px 6px rgb(0 0 0 / 10%);
    .lg_loginbox_title {
      position: relative;
      padding-bottom: 16px;
      font-size: 18px;
      color: #111;
      line-height: 1;
      font-family: PingFangSC-Medium, 'Microsoft YaHei', SimSun, Tahoma, Verdana, Arial, sans-serif;
    }
    .form_wrap {
      dl {
        padding: 8px 0;
        clear: both;
        &:after {
          clear: both;
          content: '.';
          display: block;
          height: 0;
          overflow: hidden;
        }
      }
      .r_input {
        position: relative;
        width: 300px;
        height: 28px;
        padding: 5px 5px 5px 13px;
        line-height: 28px;
        border: 1px solid #ccc;
        font-size: 14px;
        color: #333;
        display: inline-block;
        vertical-align: middle;
        &.input_country-code {
          width: 265px;
          padding-right: 40px;
          .link_code {
            display: inline-block;
            background: url('../assets/images/un_login_20170818.png') no-repeat;
            position: absolute;
            right: 0;
            top: 0;
            width: 40px;
            height: 40px;
            background-position: 0 -20px;
            vertical-align: middle;
          }
        }
        &.input_auth-code {
          width: 225px;
          padding-right: 80px;
          input {
            border: none;
            width: 200px;
            height: 28px;
            line-height: 28px;
            outline: 0;
            font-size: 14px;
            background: #fff;
          }
          a {
            position: absolute;
            right: 0;
            top: 0;
            width: 80px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 12px;
          }
          &.dynamic a {
            color: #3882e5;
          }
        }
      }
      .login-set {
        margin: 4px 0 13px;
        .auto-login {
          line-height: 1;
          font-size: 12px;
          input {
            margin-right: 5px;
            vertical-align: -2px;
          }
        }
      }
      .form_btn {
        background-color: #ff9a14;
        width: 220px;
        height: 42px;
        color: #fff;
        font-size: 16px;
        cursor: pointer;
        border: 0;
        border-radius: 4px;
        clear: both;
        -webkit-appearance: none;
        text-align: center;
      }
      .form_btn--block {
        width: 100%;
      }
      .agreement-list {
        margin-top: 5px;
        color: #999;
        line-height: 12px;
        text-align: center;
        font-size: 12px;
        a {
          padding: 0 3px;
          color: #999;
          border-bottom: 1px dotted #999;
        }
      }
      .go_prev-step {
        display: block;
        margin-top: 30px;
        color: #3882e5;
        line-height: 12px;
        font-size: 12px;
        i {
          color: #3882e5;
          font-size: 13px;
          width: 12px;
          display: inline-block;
          font-family: simsun;
          font-style: normal;
          font-weight: 700;
        }
      }
    }
    .login-code {
      position: absolute;
      top: 10px;
      right: -32px;
      background: #3882e5;
      -webkit-box-shadow: 0 1px 6px 0 rgb(0 0 0 / 10%);
      box-shadow: 0 1px 6px 0 rgb(0 0 0 / 10%);
      a {
        font-size: 13px;
        color: #fff;
        line-height: 16px;
        padding: 9px;
        width: 14px;
        height: 86px;
        display: block;
      }
      .icon-ercode {
        display: inline-block;
        vertical-align: middle;
        background: url('../assets/images/un_login_20170818.png') no-repeat;
        width: 13px;
        height: 13px;
        background-position: -20px 0;
      }
    }
  }
}
dd {
  position: relative;
  .icon-delete {
    position: absolute;
    right: 5%;
    top: 50%;
    transform: translateY(-50%);
  }
}
</style>